﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MasterDetails.aspx.cs" Inherits="ShoppingApp.MasterDetails" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style="float: left; width: 300px">
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource1" DataTextField="Name" 
            DataValueField="Addr_Id">
        </asp:DropDownList>
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ShoppingAppDbConnectionString %>" 
            SelectCommand="SELECT [Name], [Addr_Id] FROM [Shops]"></asp:SqlDataSource>
        
    </div>
    <div style="float: right; width: 300px">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="Addr_Id" DataSourceID="SqlDataSource2" Width="300px" 
            onrowdatabound="GridView1_RowDataBound">
            <Columns>
                <asp:BoundField DataField="Addr_Id" HeaderText="Addr_Id" InsertVisible="False" 
                    ReadOnly="True" SortExpression="Addr_Id"/>
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Street" HeaderText="Street" 
                    SortExpression="Street" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ShoppingAppDbConnectionString %>" 
            SelectCommand="SELECT [Addr_Id], [City], [Street] FROM [Addresses] WHERE ([Addr_Id] = @Addr_Id)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="Addr_Id" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    <div style="clear: both">
        <p>
            New Part:
        </p>
    </div>
    <div>
        <asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1" 
            DataKeyNames="Addr_Id">
            <Columns>
                <asp:CommandField SelectText="Details" ShowSelectButton="True" />
            </Columns>
        </asp:GridView>
        <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
            AllowPaging="True" AutoGenerateRows="False" DataKeyNames="Addr_Id" 
            DataSourceID="SqlDataSource3">
            <Fields>
                <asp:BoundField DataField="Addr_Id" HeaderText="Addr_Id" InsertVisible="False" 
                    ReadOnly="True" SortExpression="Addr_Id" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Street" HeaderText="Street" 
                    SortExpression="Street" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ShoppingAppDbConnectionString %>" 
            SelectCommand="SELECT [Addr_Id], [City], [Street] FROM [Addresses] WHERE ([Addr_Id] = @Addr_Id)">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView2" Name="Addr_Id" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    <div>
        <p>Details on another page:</p>
        <asp:GridView ID="GridView3" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" DataSourceID="SqlDataSource4" PageSize="5">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Addr_Id" HeaderText="Addr_Id" 
                    SortExpression="Addr_Id" />
                <asp:HyperLinkField DataNavigateUrlFields="Addr_Id" 
                    DataNavigateUrlFormatString="MasterDetails2.aspx?addrid={0}" Text="Details" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ShoppingAppDbConnectionString %>" 
            SelectCommand="SELECT [Name], [Addr_Id] FROM [Shops]"></asp:SqlDataSource>
    </div>
    
    
</asp:Content>
